package metier.sess;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import metier.entities.Devise;
import metier.entities.categorie;


@Stateless(name="DEV")
public class DeviseEJBImpl implements IDeviseRemote,IDeviseLocal{

	@PersistenceContext(unitName="PU_Cargaison")
	private EntityManager em;
	@Override
	public void addDevise(Devise d) {
		em.persist(d);
	}

	@Override
	public List<Devise> getAllDevises() {
		Query req=em.createQuery("select d from Devise d");
		return req.getResultList();
	}
	
	@Override
	public List<Devise> getAllActiveDevises() {
		Query req=em.createQuery("select d from Devise d where d.Statut=true");
		return req.getResultList();
	}

	
	@Override
	public Devise getDevise(Integer Id) {
		Devise de=em.find(Devise.class, Id);
		if(de==null)throw new RuntimeException("Devise introuvable");
		return de;
	}

	
	@Override
	public void updateDevise(Devise d) {
		em.merge(d);
	}

	
	@Override
	public void deleteDevise(Integer Id) {
		Devise dev=getDevise(Id);
		em.remove(dev);
	}

	
}
